JavaScript Testing with Jasmine by Evan Hahn

JavaScript Testing with Jasmine by Evan Hahn
Author: Evan Hahn
Language: eng
Format: epub, pdf
Tags: COMPUTERS / Programming Languages / JavaScript
ISBN: 9781449356743
Publisher: O’Reilly Media
Published: 2013-03-24

expect(8).toBeGreaterThan(5); expect(5).toBeLessThan(12); expect("a").toBeLessThan("z"); // Notice that it works for strings too!

Not too difficult!

Nearness: toBeCloseTo

toBeCloseTo allows you to check if a number is close to another number, given a certain amount of decimal precision as the second argument.

If you want to make sure that a variable is close to 12.3 within one decimal point, you’d code it like this:


expect(12.34).toBeCloseTo(12.3, 1); // success

If you want it to be the same within two decimal points, you’d change the 1 to a 2. This spec will fail, though—they differ at the second decimal digit: